--[[ 编码: JX-24-11 名称: 点领用按钮后 作者:HAN 日期:2025-1-29 级别:项目 函数: ClickOkButton 功能: -- 点击领用按钮后通过选中的出库单,统计出库货品的总体积计算出需要多少个检料框 更改记录: V2.0 HAN 20250312 增加对选中出库的的状态和波次号检测,检查是否已经有出库波次用到这个出库单 --]] wms_out = require( "wms_outbound" ) wms_station = require( "wms_station" ) -- 排序 体积大的在前面 local function sum_detail_sort( item1, item2 ) return item1.volume > item2.volume end -- 计算拣料箱的数量 -- sum_detail_list 出库单货品明细 { item_code, qty, volume } local function count_picking_box_num( strLuaDEID, sum_detail_list, box_volume ) local n local picking_box_list = { { x_volume = box_volume } } if ( box_volume == nil or box_volume <= 0 ) then return 1, "拣料箱的体积不合法必须大于0" end -- sum_detail_list 排序一下,体积大的先放 table.sort( sum_detail_list, sum_detail_sort ) local m, find, nCount for n = 1, #sum_detail_list do if ( sum_detail_list[n].volume <= 0 ) then return 1, "货品编码 = '"..sum_detail_list[n].item_code.."' 的体积不合法 !" end while ( sum_detail_list[n].qty > sum_detail_list[n].alloc_qty ) do -- 计算一个箱子能放多少个 find = false nCount = #picking_box_list for m = 1, nCount do if ( picking_box_list[m].x_volume >= sum_detail_list[n].volume ) then picking_box_list[m].x_volume = picking_box_list[m].x_volume - sum_detail_list[n].volume sum_detail_list[n].alloc_qty = sum_detail_list[n].alloc_qty + 1 find = true break end end if ( find == false ) then -- 需要申请空的拣料箱 if ( nCount == 10 ) then return 1, "拣料箱的数量不能超过10只!" end local picking_box = { x_volume = box_volume } table.insert( picking_box_list, picking_box ) end end end return 0, #picking_box_list end function ClickOkButton ( strLuaDEID ) local nRet, strRetInfo, n local data_json -- 在此操作的数据对象主体 是【出库单】数据对象, data_json 是出库单 nRet, data_json = m3.GetSysDataJson( strLuaDEID ) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), data_json ) end -- nCount 出库单数量 local nCount = #data_json if ( nCount == 0 ) then mobox.setInfo( strLuaDEID, "必须选中一个出库单!" ) return end -- 从入库单这里获取 仓库、库区编码,如果不一样报错 local wh_code = '' local area_code = '' local compose = {} -- 波次组成对象 local sum_detail_list = {} local bWave = false local bs_no, bs_type -- 获取输入界面中的工作台属性 nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_STATION_NO" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end local input_value = json.decode( strRetInfo ) local station = lua.Get_StrAttrValue( input_value[1].value ) if ( station == '' or input_value == nil ) then mobox.setInfo( strLuaDEID, "必须选择一个工作站!" ) return end local strUserLogin, strUserName nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID ) if ( nRet ~= 0 ) then return 2, "获取当前操作人员信息失败! "..strUserLogin end local box_volume = wms_base.Get_nConst( strLuaDEID, "拣料箱体积") if ( box_volume <= 0 ) then mobox.setInfo( strLuaDEID, "'拣料箱体积'参数非法!" ) return end local box_num local loc_code nRet, loc_code = wms_station.Get_Station_Loc( strLuaDEID, station ) if ( nRet ~= 0 ) then lua.Stop( strLuaDEID, loc_code ) return end local exit_loc nRet, exit_loc = wms_wh.GetLocInfo( loc_code ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '获取站台货位信息失败! '..loc_code ) end --【step1】获取出库单明细,如果是多个出库单合并出库单 local outbound_sum_info -- 出库单里货品的汇总信息比如体积 local strUpdateSql, strCondition local nPickingBoxNum = 0 bs_type = "Outbound_Wave" local outbound_obj = {} local msg = "" -- 多个出库单需要合并为一个出库波次进行出库获取出库波次明细 for n = 1, nCount do -- V2.0 -- 获取出库单对象 nRet, outbound_obj = m3.GetDataObject( strLuaDEID, "Outbound_Order", data_json[n].id ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), outbound_obj ) end -- 如果选择的出库单已经有出库波次号 if ( outbound_obj.wave_no ~= '' or outbound_obj.b_state ~= 0 ) then msg = msg.."\r\n单号='"..outbound_obj.no.."'的出库单已经有出库波次!" else if ( wh_code == '' ) then wh_code = lua.Get_StrAttrValue( outbound_obj.wh_code ) else if ( wh_code ~= outbound_obj.wh_code ) then mobox.setInfo( strLuaDEID, "选中的出库单仓库必须是一样的!" ) return end end if ( area_code == '' ) then area_code = lua.Get_StrAttrValue( outbound_obj.area_code ) else if ( area_code ~= outbound_obj.area_code ) then mobox.setInfo( strLuaDEID, "选中的出库单库区必须是一样的!" ) return end end -- 获取出库单明细 nRet, outbound_sum_info = wms_out.Sum_outbound_detail( strLuaDEID, outbound_obj.no, sum_detail_list ) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "wms_out.Sum_outbound_detail 失败!"..outbound_sum_info ) end -- 计算出库单需要多少个拣料箱,并且更新出库单 nRet, box_num = count_picking_box_num( strLuaDEID, sum_detail_list, box_volume ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "count_picking_box_num 失败!"..box_num ) end local item = { oo_no = outbound_obj.no, pick_box_num = box_num } table.insert( compose, item ) strUpdateSql = "N_PICKING_BOX_NUM = "..box_num strCondition = "S_NO = '"..outbound_obj.no.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Outbound_Order", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【出库单】信息失败!"..strRetInfo ) end nPickingBoxNum = nPickingBoxNum + box_num end end if ( wh_code == '' ) then mobox.setInfo( strLuaDEID, "出库单仓库不能为空!" ) return end local good_type_num = #sum_detail_list if ( good_type_num == 0 ) then mobox.setInfo( strLuaDEID, "出库货品不能为空!" ) return end -- V2.0 -- 如果有选中的出库单不符合要求,前端显示一下 if ( msg ~= '' ) then mobox.setInfo( strLuaDEID, msg ) end -- 统计出库货品的总体积,总重量,种类,件数 local total_qty = 0 local total_weight = 0 local total_volume = 0 if ( box_volume <= 0 ) then mobox.setInfo( strLuaDEID, "常量'拣料箱体积'必须大于0!") return end for n = 1, good_type_num do total_qty = total_qty + sum_detail_list[n].qty total_weight = total_weight + sum_detail_list[n].qty*sum_detail_list[n].weight total_volume = total_volume + sum_detail_list[n].qty*sum_detail_list[n].volume end lua.Debug( strLuaDEID, debug.getinfo(1), "STEP1 -- sum_detail_list ", sum_detail_list) -- 弹出 一个HTML界面显示 拣料箱的数量 local action = { { action_type = "refresh", value = "" }, { action_type = "open_form_dlg", value = { dlg_name = "拣货料箱绑定", cls_id = "Outbound_Order", input_parameter = { bs_type = bs_type, bs_no = bs_no, login = strUserLogin, user_name = strUserName, good_type_num = good_type_num, total_qty = total_qty, total_weight = total_weight, total_volume = total_volume, picking_box_num = nPickingBoxNum, o_detail_list = sum_detail_list, wh_code = wh_code, area_code = area_code, exit_loc = exit_loc, wave_compose = compose, station = station }, data_object = { id = "", attrs = { Station = station, PickingBoxNum = nPickingBoxNum, GoodTypeNum = good_type_num, Qty = total_qty } } } } } nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction失败! "..strRetInfo..' action = '..strAction ) end end